import {
  Column,
  PrimaryGeneratedColumn,
  ManyToOne,
  JoinColumn,
  CreateDateColumn,
  UpdateDateColumn
} from 'typeorm'
import { EntityModel } from '@midwayjs/orm'

@EntityModel('department')
export class Department {

  @PrimaryGeneratedColumn()
  id: number;

  @Column({
    comment: '部门描述，长度不应超过 100 字符',
    length: 100
  })
  name: string;

  // 父级
  @ManyToOne(() => Department, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'parent_id' })
  parent: Department;

  @CreateDateColumn({
    comment: '创建时间'
  })
  create_at: Date;

  @UpdateDateColumn({
    comment: '更新时间'
  })
  update_at: Date;
}
